<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form action="http://xxx.com/register" id="registerForm" method="post">
    请输入用户名:<input type="text" name="userName"/>
    请输入密码:<input type="text" name="password"/>
    请输入手机号码: <input type="text" name="phoneNumber">
    <button>提交</button>

</form>
<script>
    var registerForm = document.getElementById('registerForm');
    registerForm.onsubmit = function () {
        if (registerForm.userName.value === "") {
            alert('用户名不能为空');
            return false;
        }
        if (registerForm.password.value.length < 6) {
            alert('密码不能小于6位');
            return false;
        }
        // !/(^1[3|5|8][0-9]{9}$)/.test( registerForm.phoneNumber.value )
        if (!/(^1[3|5|8][0-9]{9}$)/.test(registerForm.phoneNumber.vlue)) {
            alert('手机号码格式不对')
            return false;
        }
    }
</script>
</body>
</html>